package za.org.jcicada.comms;

import java.io.IOException;
import java.nio.ByteBuffer;

import za.org.jcicada.comms.messages.CommsMessage;

public interface ICommsBuffer {

    /**
     * Convert a message to a byte buffer for sending.
     *
     * @param message  Message to convert to bytes.
     * @return byte buffer representing message.
     * @throws IOException if the message cannot be converted.
     */
    public ByteBuffer toByteBuffer(CommsMessage message) throws IOException;

    /**
     * Process a ByteBuffer, adding any messages to the internal message queue.
     *
     * @param buffer Byte buffer to feed into the internal message queue.
     * @throws IOException if the data in the byte buffer cannot be parsed.
     */
    public void feedByteBuffer(ByteBuffer buffer) throws IOException;

    /**
     * Pop a message from the internal message queue.
     *
     * @return The next message in the queue or null if the queue is empty.
     */
    public CommsMessage popMessage();

}
